package com.duk.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper{

	private static final int VERSION = 1;
	//在SQLiteOepnHelper的子类当中，必须有该构造函数
	public DatabaseHelper(Context context,String name,CursorFactory factory,int version){
		//必须通过super调用父类当中的构造函数
		super(context,name,factory,version);
	}
	
	public DatabaseHelper(Context context,String name,int version){
		this(context,name,null,version);
	}
	
	public DatabaseHelper(Context context,String name){
		this(context,name,VERSION);
	}
	
	//该函数是在第一次创建数据库的时候执行,实际上是在第一次得到SQLiteDatabse对象的时候，才会调用这个方法
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		System.out.println("create a Database");
		//execSQL函数用于执行SQL语句
		db.execSQL("CREATE TABLE favorite (id INTEGER primary key autoincrement ,news_id text ,title text ,content text ,url text , image_path text , news_type INTEGER , webdata text,pubdate text);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		System.out.println("update a Database");
		db.execSQL("DROP TABLE IF EXISTS favorite;");
	    onCreate(db);
	}
	
}
